package com.ybkj.daijia.server.controller;

import com.ybkj.daijia.common.Result;
import com.ybkj.daijia.server.exception.NoPermissionException;
import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.server.model.PeccancyAndComplain;
import com.ybkj.daijia.server.service.PeccancyAndComplainService;
import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 违章与投诉
 *
 * @author jacklee
 */
@Controller
@RequestMapping(value = "peccancyAndComplain")
public class PeccancyAndComplainController {

    @Autowired
    private PeccancyAndComplainService peccancyAndComplainService;

    /**
     * 创建违章与投诉信息
     *
     * @param peccancyAndComplain
     * @return
     */
    @RequestMapping("create")
    public @ResponseBody
    Result<PeccancyAndComplain> create(PeccancyAndComplain peccancyAndComplain) {
        Subject subject = SecurityUtils.getSubject();
        Result<PeccancyAndComplain> result = new Result<PeccancyAndComplain>();
        result.setSuccess(false);
        if (subject.isPermitted("zhuan")) {
            try {
                peccancyAndComplainService.insert(peccancyAndComplain);
                result.setSuccess(true);
            } catch (Exception e) {

                e.printStackTrace();
            }
        } else {
            result.setMessage("您没有该权限");
        }
        return result;
    }

    @RequestMapping("peccancyAndComplainData")
    public @ResponseBody
    Page<PeccancyAndComplain> peccancyAndComplainDataListData(
        @RequestParam("driverId") Long driverId) {
        Subject subject = SecurityUtils.getSubject();

        if (subject.isPermitted("zhuan")) {

            Page<PeccancyAndComplain> result = peccancyAndComplainService.queryByEmploy(driverId);

            return result;
        } else {
            throw new NoPermissionException();
        }

    }

    @RequestMapping("test")
    public @ResponseBody
    String test(HttpServletRequest request) {

        String PayName = request.getParameter("PayName");

        return "测试信息参数乱码";
    }

}
